package com.ac.action;

import java.util.List;

import com.ac.entity.Parts;
import com.ac.entity.PartsRecord;
import com.ac.entity.PartsType;
import com.ac.util.DataStore;


public class PartsAction extends PartsTypeAction{

	/**
	 * 
	 */
	
	private Parts parts;
	
	private static final long serialVersionUID = 1L;
	
	

	@Override
	public String execute() {
		partsTypeList = this.getHibernateBaseDao().getAllList(PartsType.class);
		return INPUT;
	}

	@Override
	public String delete() {
		this.getHibernateBaseDao().delete(parts);
		DataStore.refresh();
		return DELETE;
	}

	@Override
	public String modify() {
		partsTypeList = this.getHibernateBaseDao().getAllList(PartsType.class);
		parts = (Parts) this.getHibernateBaseDao().getObjectByKey(parts.getClass(), parts.getId());
		return INPUT;
	}

	public Parts getParts() {
		return parts;
	}

	public void setParts(Parts parts) {
		this.parts = parts;
	}

	@Override
	public String confirm() {
		this.getHibernateBaseDao().saveOrUpdate(parts);
		String sql = "select a.*,c.name as typeName from ac_parts a left join ac_parts_type as c on a.typeId = c.id where a.id = " + parts.getId();
		parts = (Parts) this.getHibernateBaseDao().getObject(sql, Parts.class);
		DataStore.refresh();
		return RESULT;
	}

	public List<PartsType> getPartsTypeList() {
		return partsTypeList;
	}

	public void setPartsTypeList(List<PartsType> partsTypeList) {
		this.partsTypeList = partsTypeList;
	}

}
